package org.ainlolcat.ainscience.statistics.handlers.hitran.instfunc;

import static java.lang.Math.*;

/**
 * @author ainlolcat
 *         Date: 5/1/13
 */
public class PsdVoigt1InstrumentalFunction implements InstrumentalFunction{
    double w;
    double mu;
    double A = 1;
    double y0 = 0;

    public PsdVoigt1InstrumentalFunction() {
    }

    public PsdVoigt1InstrumentalFunction( double y0, double A, double w, double mu){
        this.w = w;
        this.mu = mu;
        this.A = A;
        this.y0 = y0;
    }

    public PsdVoigt1InstrumentalFunction(double w, double mu){
        this.w = w;
        this.mu = mu;
    }

    public void setParameters(double[] params) {
        this.w = params[0];
        this.mu = params[1];
        this.A = params[2];
        this.y0 = params[3];
    }

    public double getValue(double dx) {
        double x2 = pow(dx,2);
        double w2 = pow(w,2);
        return  y0 + A * (
                        mu * (2/PI) * (w / (4 * x2  + w2)) +
                        (1-mu) * (sqrt(4 * log(2))/(sqrt(PI) * w)) * exp( - (4 * log(2) / w2) * x2)
                    );
                //(A/(w*Math.sqrt(PI/2)))*Math.exp(-2 * Math.pow(dx, 2) / (Math.pow(w, 2)));
    }

    public boolean equals(Object o){
        if (o instanceof PsdVoigt1InstrumentalFunction){
            return w == ((PsdVoigt1InstrumentalFunction)o).w;
        }
        return false;
    }
}
